package com.wenjh.jdmzt.service.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.wenjh.jdmzt.service.model.User;

public class UserDao extends BaseDao<User, String> implements User.Table {

	public UserDao(SQLiteDatabase db) {
		super(db, TableName, F_ID);
	}

	@Override
	public void insert(User t) {
		insert(new String[] {
			F_PhoneNumber,
			F_WorkUnit,
			F_ID,
			F_Name,
			F_WorkLength
		}, new Object[]{
			t.phonenumber,
			t.workunit,
			t.id,
			t.name,
			t.workLength
		});
	}

	@Override
	public void update(User t) {
		updateField(new String[]{
				F_PhoneNumber,
				F_WorkUnit,
				F_Name,
				F_WorkLength
		}, new Object[]{
				t.phonenumber,
				t.workunit,
				t.name,
				t.workLength
		}, new String[]{
				F_ID
		}, new Object[]{
				t.id
		});
	}

	@Override
	public void deleteInstence(User obj) {
		delete(obj.id);
	}
	
	@Override
	protected void assemble(User user, Cursor cursor) {
		
		user.phonenumber = cursor.getString(cursor.getColumnIndex(F_PhoneNumber));
		user.name = cursor.getString(cursor.getColumnIndex(F_Name));
		user.workunit = cursor.getString(cursor.getColumnIndex(F_WorkUnit));
		user.id = cursor.getString(cursor.getColumnIndex(F_ID));
		user.workLength = cursor.getInt(cursor.getColumnIndex(F_WorkLength));
		
	}

	@Override
	protected User assemble(Cursor cursor) {
		User user = new User();
		assemble(user, cursor);
		return user;
	}

}
